1 00:00:00,150 --> 00:00:05,640 So now that I have my badge created in Roblox, I want to be able to award it to players when they first 2 00:00:05,640 --> 00:00:07,220 triggered the boulder trap. 3 00:00:07,230 --> 00:00:09,990 And this is my boulder trap right here. 4 00:00:10,020 --> 00:00:14,700 Trigger It is the script that actually triggers the boulder trap to go. 5 00:00:14,700 --> 00:00:16,170 So that's what I want. 6 00:00:16,170 --> 00:00:18,780 I'm going to open my trigger now. 7 00:00:18,780 --> 00:00:22,620 I need a variable for the badge ID I created. 8 00:00:22,740 --> 00:00:31,920 I'm going to call this beat for Boulder Trap Badge ID If you don't have the badge ID, we could go to 9 00:00:31,920 --> 00:00:33,120 the website. 10 00:00:33,120 --> 00:00:34,770 This is from the last video. 11 00:00:34,800 --> 00:00:37,980 Hit those three dots for your badge that you created. 12 00:00:37,980 --> 00:00:39,720 Copy Asset ID. 13 00:00:39,960 --> 00:00:43,140 Go back to your code control V. 14 00:00:43,170 --> 00:00:44,250 There you go. 15 00:00:44,520 --> 00:00:46,400 I said ID of the badge. 16 00:00:46,410 --> 00:00:54,690 Now we also need the badge service, so I'm going to call that B service for bad service as a game. 17 00:00:55,320 --> 00:00:58,200 Get service, Badge service. 18 00:00:58,200 --> 00:01:01,170 So this badge service is going to be in this variable right here. 19 00:01:02,010 --> 00:01:02,280 All right. 20 00:01:02,280 --> 00:01:05,490 Now I'm going to make a function local function. 21 00:01:05,490 --> 00:01:12,450 I'm going to call this award badge and I'm going to make this general so that if I want to do badges 22 00:01:12,450 --> 00:01:14,700 elsewhere, I could just copy and paste it. 23 00:01:14,970 --> 00:01:16,590 I'm going to pass in a player. 24 00:01:16,680 --> 00:01:22,590 The person is going to get the badge, I'm going to pass in a variable for the badge ID, but I'm not 25 00:01:22,590 --> 00:01:26,790 going to make it specific to this badge because I might want to use this code elsewhere. 26 00:01:27,810 --> 00:01:36,960 I'm going to make a variable, a Boolean variable that's has badge and we'll initialize it to false 27 00:01:37,350 --> 00:01:39,750 because we don't want to award it more than once. 28 00:01:40,080 --> 00:01:45,780 And then I'm going to use an asynchronous call to Roblox to see if the person actually got the badge. 29 00:01:45,960 --> 00:01:50,730 But I'm going to wrap that in something called the P call, a protected call. 30 00:01:50,730 --> 00:01:52,500 It's kind of a weird pattern. 31 00:01:52,500 --> 00:01:54,990 It'll take a while to get used to, right? 32 00:01:54,990 --> 00:01:58,290 It took me a while to get used to and I was a programmer already. 33 00:01:58,290 --> 00:02:00,960 So we'll do this local. 34 00:02:00,960 --> 00:02:02,910 We'll declare two variables. 35 00:02:03,690 --> 00:02:10,980 It's going to be success and message, and this is what we're going to get back from the p call, right? 36 00:02:10,980 --> 00:02:12,120 Just like that. 37 00:02:12,120 --> 00:02:17,010 And then I'm going to put an anonymous function inside the call. 38 00:02:17,010 --> 00:02:18,920 So we are protecting this. 39 00:02:18,990 --> 00:02:23,640 A protected call is going to give us status on how that asynchronous call went. 40 00:02:23,640 --> 00:02:29,820 So like if your brother kicks out the Internet cable or something, you will get the error and message 41 00:02:29,820 --> 00:02:30,570 is going to tell you. 42 00:02:30,570 --> 00:02:36,090 You're going to give you a hint of what it is success or failure is going to be, whether it went through 43 00:02:36,090 --> 00:02:39,420 or there's a problem detected from the p call. 44 00:02:39,750 --> 00:02:40,860 It's kind of clever. 45 00:02:40,860 --> 00:02:49,200 So what we're going to do is we're going get this has badge boolean and set it equal to the badge services 46 00:02:49,200 --> 00:02:56,760 result from user has badge async call. 47 00:02:56,760 --> 00:02:57,210 Right. 48 00:02:57,210 --> 00:03:06,030 We need to pass in the players user ID and the badge ID and that's going to go to roadblocks and say, 49 00:03:06,030 --> 00:03:07,470 Hey, does this guy have the badge? 50 00:03:07,470 --> 00:03:09,990 If he does, it's true. 51 00:03:09,990 --> 00:03:13,980 If he doesn't, if he does, if it's if he doesn't, it's false. 52 00:03:13,980 --> 00:03:14,490 Right. 53 00:03:14,490 --> 00:03:18,150 But we're also going to check to make sure that we didn't run into problems here. 54 00:03:19,050 --> 00:03:25,470 So we've got to do some sort of statement like, if not success, the recall. 55 00:03:25,710 --> 00:03:27,510 Notice that there is an error. 56 00:03:27,540 --> 00:03:33,480 Maybe the Internet went out or something went to say warn, this will be for troubleshooting. 57 00:03:34,020 --> 00:03:38,580 Something went wrong. 58 00:03:38,580 --> 00:03:42,780 What's wrong with the call? 59 00:03:43,410 --> 00:03:50,880 Well, let's do with the with the badge call and then we can put the message right here. 60 00:03:51,550 --> 00:03:51,940 Right. 61 00:03:52,230 --> 00:03:55,860 And then what we're going to do is we're just going to return, right? 62 00:03:55,860 --> 00:03:57,330 So something went wrong. 63 00:03:57,900 --> 00:03:58,670 They didn't get there. 64 00:03:58,800 --> 00:04:03,300 We're not going to give them the badge, but we'll just leave right there. 65 00:04:03,300 --> 00:04:05,530 And that way they can always get it again, right. 66 00:04:05,550 --> 00:04:12,150 I'm not going to do a loop or anything just to make sure it's it's overkill, I think, for the badge. 67 00:04:12,150 --> 00:04:20,430 So we'll say if the if has badge, let's say if has badge equals false, Right. 68 00:04:20,430 --> 00:04:22,290 They don't have the badge. 69 00:04:22,290 --> 00:04:24,000 How else can we write that. 70 00:04:24,000 --> 00:04:25,260 Lots of ways. 71 00:04:25,350 --> 00:04:26,880 Probably a better way. 72 00:04:26,880 --> 00:04:28,230 You can leave it like this if you want. 73 00:04:28,230 --> 00:04:29,580 I'm just going to show you another way. 74 00:04:30,330 --> 00:04:35,340 You could say if not has badge right two ways. 75 00:04:35,940 --> 00:04:37,950 Then we're going to say B service. 76 00:04:40,350 --> 00:04:42,510 We're going to award the badge. 77 00:04:42,510 --> 00:04:44,930 There it is, award badge. 78 00:04:45,180 --> 00:04:52,530 We'll pass in the player, the player user ID, right, The player user ID, and then we're going to 79 00:04:52,530 --> 00:04:53,820 get our badge number. 80 00:04:53,820 --> 00:04:55,500 What is our badge number? 81 00:04:57,600 --> 00:04:59,550 The badge ID, I set it wrong. 82 00:05:00,250 --> 00:05:03,800 Passing the badge ID that should do it. 83 00:05:03,820 --> 00:05:09,690 We could put a little troubleshooting in here like, Well, let's just go ahead and do an LS. 84 00:05:09,700 --> 00:05:10,040 Right? 85 00:05:10,060 --> 00:05:11,150 Else they do have a badge. 86 00:05:11,150 --> 00:05:14,020 We'll put a little message just so we know we're touching it. 87 00:05:14,020 --> 00:05:14,650 Right. 88 00:05:14,650 --> 00:05:16,870 You have the badge. 89 00:05:18,310 --> 00:05:19,630 That's pretty cool. 90 00:05:19,840 --> 00:05:20,230 All right. 91 00:05:20,230 --> 00:05:20,560 That's what. 92 00:05:20,680 --> 00:05:21,400 That's all you need. 93 00:05:21,400 --> 00:05:23,500 Let's go ahead and copy this. 94 00:05:23,500 --> 00:05:23,690 Right. 95 00:05:23,710 --> 00:05:25,120 We're going to copy that, Control. 96 00:05:25,120 --> 00:05:29,680 See, we're going to go down to our on touch. 97 00:05:29,680 --> 00:05:36,580 And then when we successfully trigger play the boulder sound, we'll just go ahead and check that. 98 00:05:36,580 --> 00:05:38,170 Oh, but we need a player. 99 00:05:38,170 --> 00:05:40,120 We do have a badge number, right? 100 00:05:40,120 --> 00:05:41,050 We have the badge number. 101 00:05:41,050 --> 00:05:44,110 We have the BT Badge ID, but we don't have a player. 102 00:05:44,110 --> 00:05:45,100 Let's get the player. 103 00:05:45,100 --> 00:05:46,390 We've got a humanoid. 104 00:05:46,420 --> 00:05:48,850 If you get a humanoid, you can get a player. 105 00:05:48,850 --> 00:05:52,420 Well, unless there's no player because Zombie might might trip it too. 106 00:05:52,420 --> 00:05:53,710 So you don't want to give it to a zombie. 107 00:05:53,710 --> 00:05:54,520 We better check. 108 00:05:54,520 --> 00:05:56,020 We better check to see if there's a player. 109 00:05:56,020 --> 00:05:58,630 So local player. 110 00:05:58,960 --> 00:06:06,280 Well, if this is a humanoid, then this would be the character, Right? 111 00:06:06,280 --> 00:06:07,600 So. 112 00:06:08,440 --> 00:06:10,510 Let's get our prayer service. 113 00:06:10,510 --> 00:06:12,610 We can do this game, players. 114 00:06:12,610 --> 00:06:23,860 That gives us the player service and then colon get player from character and other part dot parent 115 00:06:23,860 --> 00:06:27,580 would be the character if the humanoid did exist. 116 00:06:27,580 --> 00:06:29,740 I'm going to put this on a second line so you could see it. 117 00:06:29,740 --> 00:06:32,300 You could leave it all on one line if you want, right? 118 00:06:32,410 --> 00:06:33,730 But that way you can see it. 119 00:06:34,420 --> 00:06:34,780 All right. 120 00:06:34,780 --> 00:06:37,480 So we theoretically have a player. 121 00:06:37,480 --> 00:06:38,320 We're not sure, though. 122 00:06:38,320 --> 00:06:39,270 It could have been a zombie. 123 00:06:39,280 --> 00:06:40,930 Zombies have humanoids. 124 00:06:41,230 --> 00:06:42,100 We got to make sure. 125 00:06:42,100 --> 00:06:48,920 So we're say if player right, if the player was returned from the player service, then we will call 126 00:06:48,920 --> 00:06:52,900 our ward badge and not otherwise we're good to go. 127 00:06:52,900 --> 00:06:55,030 We should be able to get this badge. 128 00:06:55,030 --> 00:06:58,570 Let's go ahead and play this game, see what we got. 129 00:06:58,990 --> 00:07:00,820 It should pop up down here. 130 00:07:06,310 --> 00:07:06,960 We go. 131 00:07:06,970 --> 00:07:08,020 Looking good. 132 00:07:10,630 --> 00:07:11,320 Let's do it. 133 00:07:12,310 --> 00:07:12,960 There it is. 134 00:07:12,970 --> 00:07:13,930 We got the badge. 135 00:07:14,140 --> 00:07:15,760 You just missed that boat or two. 136 00:07:16,180 --> 00:07:19,330 All right, so now you know how to add badges to your game. 137 00:07:19,330 --> 00:07:20,290 And the next video. 138 00:07:20,290 --> 00:07:22,450 I'm going to just show you how to delete it from your account. 139 00:07:22,450 --> 00:07:25,060 So if you test this, you don't have to make, like, 20 badges, right? 140 00:07:25,060 --> 00:07:28,780 Because you don't want to you don't have to get a new one every time you test.